<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="${ctx}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="${ctx}/static/css/basic.css" rel="stylesheet" type="text/css">
    <link href="${ctx}/static/plugins/validationEngine/css/validationEngine.jquery.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        .btn-sm {
            border-width: 4px;
            font-size: 13px;
            padding: 4px 9px;
            line-height: 1.39;
        }

        .code_space {
            margin-left: -4px;
            margin-right: 14px;
        }

        .btn_key {
            background-color: #6fb3e0 !important;
            border-color: #6fb3e0;
        }

        .btn_key:hover {
            color: #fff;
            background-color: #39b3d7;
            border-color: #269abc;
        }

        .code_width {
            width: 36.5%;
        }

        @media only screen and (max-width: 767px ) {
            .code_width {
                width: 102%;
            }
        }

        .radios {
            margin-bottom: 20px;
            float: left;
            margin-left: 40px;

        }
        .col-sm-area{
            width: 50%;
        }
    </style>
</head>
<body>
<div class="content">
    
	<!-- 数据Form -->
    <form class="form-horizontal" id="updateForm">
        <br>
        <br>
        <br>
        <div style="display:none;">
            <label for="id" class="col-sm-4 control-label">主键:</label>
            <div class="col-sm-3">
                <input type="text" class="form-control validate[required]" id="id" name="id" value="${warehouseAddress.id}" placeholder="主键">
            </div>
        </div>
        <div class="form-group">
            <label for="contacts" class="col-sm-4 control-label"><span style="color:red;">*</span>联系人:</label>
            <div class="col-sm-3">
                <input type="text" class="form-control validate[required]" id="contacts" name="contacts" value="${warehouseAddress.contacts}" placeholder="请输入联系人">
            </div>
        </div>
        <div class="form-group">
            <label for="telPhone" class="col-sm-4 control-label"><span style="color:red;">*</span>联系电话:</label>
            <div class="col-sm-3">
                <input type="text" class="form-control validate[required,custom[phone]]" id="telPhone" name="telPhone" value="${warehouseAddress.telPhone}" readonly="readonly"  data-fun="dataFunDemo" placeholder="请输入联系电话">
            </div>
        </div>
        <div class="form-group">
            <label for="phoneNo" class="col-sm-4 control-label">座机号:</label>
            <div class="col-sm-3">
                <input type="text" class="form-control" id="phoneNo" name="phoneNo"  value="${warehouseAddress.phoneNo}" data-fun="dataFunDemo" placeholder="请输入推广师电话">
            </div>
        </div>
        <div class="form-group">
            <label for="area_div" class="col-sm-4 control-label"><span style="color:red;">*</span>所属区域:</label>
            <div id="area_div" style="width: 600px;height:27px;display:inline;"></div>
        </div>
        <div class="form-group">
            <label for="address" class="col-sm-4 control-label"><span style="color:red;">*</span>详细地址:</label>
            <div class="col-sm-3">
                <input type="text" class="form-control validate[required]" id="address" name="address" value="${warehouseAddress.address}" data-fun="dataFunDemo" placeholder="请输入详细地址">
            </div>
        </div>
        <div class="form-group">
            <label for="description" class="col-sm-4 control-label"><span style="color:red;">*</span>是否默认地址:</label>
            <div class="col-sm-3">
            	<select name="isDefault" id="isDefault" class="form-control validate[required]">   
			        <option value="1">是</option>   
			        <option value="2">否</option>   
			    </select>
            </div>
        </div>
        <div class="form-group">
            <label for="isDeliveryPoint" class="col-sm-4 control-label"><span style="color:red;">*</span>是否提货点:</label>
            <div class="col-sm-3">
            	<select name="isDeliveryPoint" id="isDeliveryPoint" class="form-control validate[required]">   
			        <option value="1">是</option>   
			        <option value="2">否</option>   
			    </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-10">
                <button type="button" id="addBtn" class="btn btn-primary">保存</button>
            </div>
        </div>
    </form>
</div>
<script src="${ctx}/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="${ctx}/static/bootstrap/js/bootstrap.min.js"></script>
<script src="${ctx}/static/plugins/layer/layer.js"></script>
<script src="${ctx}/static/plugins/validationEngine/jquery.validationEngine-zh_CN.js"></script>
<script src="${ctx}/static/plugins/validationEngine/jquery.validationEngine.js"></script>
<script src="${ctx}/static/js/common/base.js" type="text/javascript"></script>
<script src="${ctx}/static/js/common/page.js" type="text/javascript"></script>
<script src="${ctx}/static/js/common/common.js" type="text/javascript"></script>
<script src="${ctx}/static/js/common/area.js" type="text/javascript"></script>
<script>

    $(function () {
    	$("#isDefault").val(${warehouseAddress.isDefault});
    	$("#isDeliveryPoint").val(${warehouseAddress.isDeliveryPoint});
    	
    	$("#updateForm").validationEngine({ 
    		promptPosition: "topRight", 
    		validationEventTriggers:"keyup blur", 
    		success :  false,
    		failure : function() { callFailFunction()  }
   		});

        $("#addBtn").click(function(){
            var flag = $("#updateForm").validationEngine("validate");
            if(!flag){
                return false;
            }
            //提交数据
            $.ajax({
                async       : false,
                type 		: "POST",
                url		    : "${ctx}/api/warehouseAddress/update",
                data 		: $("#updateForm").serialize(),
                success 	: function( d ) {
                	if(d.code=="200"){
        				alert("仓库地址修改成功!");
        				window.location.href="${ctx}/api/warehouseAddress/listPage"
        			} else {
        				alert(d.message);
        			}
                }
            });
        });
    });

    
// 	//区域下拉框
//     var data ={
//             provinceId:${warehouseAddress.provinceId},
//             cityId:${warehouseAddress.cityId},
//             areaId:${warehouseAddress.areaId},
//         };
    
// 	//区域下拉框
// 	 areaAll({
// 		url: "/api/merchant/getAllPosition",
// 		startFun:function(){
// 			$("#area_div").find(".formError").remove();
// 		},
// 		totalSelect:3,
// 	    DivId: "area_div",
// 	    selectWidthArr: ["90px", "90px", "90px", "90px"],
// 	    areaArr: ["省份:","市:", "区县:","社区:"],
// 	    idArr: ["provinceId", "cityId", "areaId","townId"],
// 	    isNeedName: false,
// 	    spaceArrLeft:[5,5,5,5],
// 	    spaceArrRight:[5,5,5,5],
// 	    data: data,
// 	    backFun: function(){
// 	    	$("select[name='provinceId']").addClass("validate[required]");
// 	    	$("select[name='cityId']").addClass("validate[required]");
// 	    	$("select[name='areaId']").addClass("validate[required]");
// 	    }
// 	});
	
		//区域下拉框
	    var data ={
	            provinceId:${warehouseAddress.provinceId},
	            cityId:${warehouseAddress.cityId},
	            areaId:${warehouseAddress.areaId},
	        };
	    
	    areaAll({
	    	url: "/api/merchant/getAllPosition",
			startFun:function(){
				$("#area_div").find(".formError").remove();
			},
			totalSelect:3,
		    DivId: "area_div",
		    selectWidthArr: ["90px", "90px", "90px", "90px"],
		    areaArr: ["省份:","市:", "区县:","社区:"],
		    idArr: ["provinceId", "cityId", "areaId","townId"],
		    isNeedName: false,
		    spaceArrLeft:[5,5,5,5],
		    spaceArrRight:[5,5,5,5],
		    data: data,
	        backFun: function(){
		    	$("select[name='provinceId']").addClass("form-control validate[required]");
		    	$("select[name='cityId']").addClass("form-control validate[required]");
		    	$("select[name='areaId']").addClass("form-control validate[required]");
// 	        	$("select[name='provinceId']").attr("disabled","disabled"); 
// 	        	$("select[name='cityId']").attr("disabled","disabled"); 
// 	        	$("select[name='areaId']").attr("disabled","disabled"); 
		    }
	    });
</script>
</body>
</html>